<!DOCTYPE HTML>
<html>
<head>
    <title>增加</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
    <div id="form1" style="padding-left: 60px">
        <span style="width:60px;display:inline-block;">商品类型：</span>
        <input id="typeName" name="typeName" class="mini-combobox" required="true" style="width:155px;"  data="typeData" value="1"/>
        <span style="width:60px;display:inline-block;">名称：</span>
        <input id="btnEdit1" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="a" textName="b"/>
        <br/><br/>
        <span style="width:60px;display:inline-block;">积分：</span>
        <input id="score" name="score" class="mini-textbox" required="true"  type="number" style="width:155px;" />
        <span style="width:60px;display:inline-block;">运费：</span>
        <input id="freight" name="freight" class="mini-textbox" required="true" type="number" style="width:155px;" value='0'/>
        <br/><br/>
        <span style="width:60px;display:inline-block;">购买数量：</span>
        <input id="count" name="count" class="mini-textbox" required="true" type="number" style="width:155px;" value="9999"/>
        <span style="width:60px;display:inline-block;">赠送积分：</span>
        <input id="presentScore" name="presentScore" class="mini-textbox" required="true" type="number" style="width:155px;" value="200"/>
        <br/><br/>
        <span style="width:60px;">商品分类：</span>
        <input id="btnSelectGoodsType" class="mini-buttonedit" onbuttonclick="onButtonSelectGoodsType"/>
        <input id="pid" name="pid" class="mini-textbox" required="true" type="number" style="width:155px;display: none;" readonly="readonly"/>
        <span style="width:100px;display:inline-block;">是否是VIP商品：</span>
        <input id="isVip" name="isVip" class="mini-combobox" style="width:100px;" data="isVipData" value="0"/>
        <br/><br/>
        <span style="width:60px;display:inline-block;">佣金总额：</span>
        <input id="brokerage" name="brokerage" class="mini-textbox" required="true" type="number" style="width:155px;" value="0"/>
        <span style="width:60px;display:inline-block;">价格：</span>
        <input id="price" name="price" class="mini-textbox" required="true" type="number" style="width:155px;" />
        <br/><br/>
        <span style="width:150px;display:inline-block;">上一级分成钱：</span>
        <input id="superiorMoney" name="superiorMoney" class="mini-textbox" type="number" style="width:155px;" value="0" onvaluechanged="priceChange"/>
        <br/><br/>
        <span style="width:150px;display:inline-block;">上二级分成钱：</span>
        <input id="superiorSuperiorMoney" name="superiorSuperiorMoney" class="mini-textbox" type="number" style="width:155px;" value="0" />
        <br/><br/>
        <span style="width:150px;display:inline-block;">上三级分成钱：</span>
        <input id="superiorSuperiorSuperiorMoney" name="superiorSuperiorSuperiorMoney" class="mini-textbox" type="number" style="width:155px;" value="0" />
        <br/><br/>
        <span style="width:150px;display:inline-block;">上三级祖辈分成钱：</span>
        <input id="ancestorsMoney" name="ancestorsMoney" class="mini-textbox" type="number" style="width:155px;" value="0"/>
        <br/><br/>
        <span style="width:150px;display:inline-block;">上一级分成积分比例：</span>
        <input id="superiorScore" name="superiorScore" class="mini-textbox" type="number" style="width:155px;" value="20"/>
        <br/><br/>
        <span style="width:150px;display:inline-block;">上二级分成积分比例：</span>
        <input id="superiorSuperiorScore" name="superiorSuperiorScore" class="mini-textbox" type="number" style="width:155px;" value="10"/>
        <br/><br/>
        <!--<span style="width:150px;display:inline-block;">上三级分成积分比例：</span>-->
        <!--<input id="superiorSuperiorSuperiorScore" name="superiorSuperiorSuperiorScore" class="mini-textbox" type="number" style="width:155px;" value="10"/>-->
        <!--<br/><br/>-->
        <span style="width:150px;display:inline-block;">上二级祖辈分成积分比例：</span>
        <input id="ancestorsScore" name="ancestorsScore" class="mini-textbox" type="number" style="width:155px;" value="10"/>
        <br/><br/>
    </div>
    <div style="margin: 30px 0;text-align: center">
        <a class="mini-button " iconCls="icon-ok" onclick="addScoreGoodShop()">确定</a>
        <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
    </div>
</body>
<script>
    var isVipData= [{id:0,text:'否'},{id:1,text:'是'}];
    var typeData = [{ id: 1, text: '普通商品' },{ id: 2, text: '站外商品' }];
    function addScoreGoodShop(){
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            alert("请正确填写数据")
            return
        };
        var data = {}
      data.shopGoodsOId = mini.get("btnEdit1").getValue();
      data.isVip = mini.get("isVip").getValue();
      data.price = mini.get("price").getValue();
      data.typeName = mini.get("typeName").getValue();
      data.score = mini.get("score").getValue();
      data.freight = mini.get("freight").getValue();
      data.count = mini.get("count").getValue();
      data.presentScore = mini.get("presentScore").getValue();
      data.superiorMoney = mini.get("superiorMoney").getValue();
      data.superiorSuperiorMoney = mini.get("superiorSuperiorMoney").getValue();
      data.superiorSuperiorSuperiorMoney = mini.get("superiorSuperiorSuperiorMoney").getValue();
      data.ancestorsMoney = mini.get("ancestorsMoney").getValue();
      data.superiorScore = mini.get("superiorScore").getValue();
      data.superiorSuperiorScore = mini.get("superiorSuperiorScore").getValue();
        // data.superiorSuperiorSuperiorScore = mini.get("superiorSuperiorSuperiorScore").getValue();
      data.ancestorsScore = mini.get("ancestorsScore").getValue();
      data.goodsTypeOId = mini.get("btnSelectGoodsType").getValue();
      data.goodsTypePId = mini.get("pid").getValue();
      data.brokerage = mini.get("brokerage").getValue();
      console.log(mini.get("brokerage"))
      // console.log(data)
      if (!data.goodsTypeOId){
        alert('请选择商品分类！')
        return
      }
      $.ajax({
        type: "POST",
        url: "/getdata/addScoreGoodsShop",
        data:data,
        success: function (result) {
          if(result =="1"){
            alert("保存成功");
            CloseWindow("save");
          }else{
            alert("保存失敗")
            CloseWindow("save");
          }
        }
      })
    }
    function clearGoods() {

      mini.get('btnEdit1').setText('');
      mini.get('btnEdit1').setValue('');
      console.log(mini.get("btnEdit1").getText())
      console.log(mini.get("btnEdit1").getValue())
    }
    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }

    function onCancel(e) {
        CloseWindow("cancel");
    }

    function onButtonEdit(e) {
      let id =  mini.get('typeName').getValue()
      if (id == 1){
        var btnEdit = this;
        mini.open({
          url: "/editor/shopGoodsChoice",
          title: "商品列表",
          width: 1100,
          height: 450,
          ondestroy: function (action) {
            if (action == "ok") {
              var iframe = this.getIFrameEl();
              var data = iframe.contentWindow.GetData();
              data = mini.clone(data);    //必须
              if (data) {
                btnEdit.setText(data.text);
                btnEdit.setValue(data.id);
              }
            }else {
              btnEdit.setText("");
            }

          }
        });
      } else {
        var btnEdit = this;

        mini.open({
          url: "/editor/externalGoodsChoice",
          title: "站外商品列表",
          width: 1100,
          height: 450,
          ondestroy: function (action) {
            if (action == "ok") {
              var iframe = this.getIFrameEl();
              var data = iframe.contentWindow.GetData();
              // console.log(data)
              data = mini.clone(data);    //必须
              if (data) {
                btnEdit.setText(data.text);
                btnEdit.setValue(data.id);
                mini.get('price').setValue(data.price);
                mini.get('count').setValue(data.salesVolumeMonth);
                mini.get('score').setValue(0);
                mini.get('presentScore').setValue(0);
                mini.get('superiorScore').setValue(0);
                mini.get('superiorSuperiorScore').setValue(0);
                mini.get('ancestorsScore').setValue(0);
                mini.get('brokerage').setValue(data.commission);

              }
            }else {
              btnEdit.setText("");
            }

          }
        });
      }


    }
    function priceChange() {
      var price = mini.get("superiorMoney").getValue()
      var superiorSuperiorMoney = Math.floor(Number(price) * 0.6 *100)/100
      mini.get('superiorSuperiorMoney').setValue(superiorSuperiorMoney.toFixed(2));
      var ancestorsMoney = Math.floor(Number(price) * 0.2 *100)/100
      mini.get('superiorSuperiorSuperiorMoney').setValue(ancestorsMoney.toFixed(2));
      var ancestorsMoney = Math.floor(Number(price) * 0.2 *100)/100
      mini.get('ancestorsMoney').setValue(ancestorsMoney.toFixed(2));
    }
    function onButtonSelectGoodsType(e) {
      var btnSelectGoodsType = this;
      mini.open({
        url: "/getdata/shopIntergationSelectGoodsType",
        showMaxButton: false,
        title: "选择商品分类",
        width: 350,
        height: 350,
        ondestroy: function (action) {
          if (action == "ok") {
            var iframe = this.getIFrameEl();
            var data = iframe.contentWindow.GetData();
            data = mini.clone(data);
            if (data) {
              // console.log(data)
              btnSelectGoodsType.setValue(data.id);
              btnSelectGoodsType.setText(data.text);
              mini.get('pid').setValue(data.pid);
            }
          }
        }
      });
    }
</script>
</html>